function  delete_article(ar_id,type,act_type)
{
	var str = "";
	var tips = '确定删除记录吗?';
	var falge = false;
	var error = 0;
	if(act_type == 'revert_article')
	{ 
		tips = '确定还原记录吗?'
	}
	
	if(type == 'list')
	{
		$('input[name="ID[]"]').each(function () 
		{
			if ($(this).attr('checked')) 
			{
				falge = true; 
				var count = parseInt($('#list_count_'+$(this).val()).html());
				if(count>0)
				{
					if(act_type == 'tag')
					{
						error = 1;
					}
				} 
				str += $(this).val() + ",";
			}
		});
		if(error == 1)
		{
			alert('你所选择的tag里有些tag下面还有文章,请选择没有文章的tag！');
			return false;
		}
		if(!falge)
		{
			alert('你没有选择任何选项！');  
			return false;
		}
	
	}else
	{
		str = ar_id+','; 
	}
	if(confirm(tips))
	{ 
		if(act_type == 'article')
		{
			$.get("/wondershare/article.php?action=index", { jax_type: 'delete_article', checkList: str ,type:'delete' },
			function(data){
			
			});
		}
		else if(act_type == 'tag')
		{
			if(type != 'list')
			{
				var count = parseInt($('#list_count_'+ar_id).html());
				if(count>0)
				{
					alert('不能删除此tag,此tag下面还有文章！');
					return false;
				}
			}
			$.get("/wondershare/tag.php?action=index", { jax_type: 'del_tag', checkList: str },
			function(data){}); 
		}
		else if(act_type == 'revert_article')
		{
			$.get("/wondershare/article.php?action=index", { jax_type: 'delete_article', checkList: str ,type:'revert'},
			function(data){});
		}
		else if(act_type == 'del_products')
		{
			$.get("/wondershare/products.php?action=index", { in_jax: 2, checkList: str ,type:'del_products'},
			function(data){});  
		}
		if(type != 'list')
		{
			$("#tr_"+ar_id).remove();
			$('#total').html(parseInt($('#total').html())-1) ;
		}else
		{
			$('input[name="ID[]"]').each(function () {
				if ($(this).attr('checked')) 
				{
					$("#tr_"+$(this).val()).remove();
					$('#total').html(parseInt($('#total').html())-1) ;
				}
			}); 
		}
	
	}
}

function  change_image(image_id,id,type,act_type)
{
	var value = 0;
	if($('#'+image_id).attr("src") == '/wondershare/images/yes.gif')
	{
		value = 0;
		$('#'+image_id).attr("src","/wondershare/images/no.gif"); 
	}else
	{
		value = 1;
		$('#'+image_id).attr("src","/wondershare/images/yes.gif");  
	}
	
	if(act_type == 'tag')
	{
		
		$.get("/wondershare/tag.php?action=index", { jax_type: 'update_hot', tag_id: id,is_hot:type,value:value, w_type:$("#w_type").val() },
		function(data){
			
			});
	}else
	{
		$.get("/wondershare/article.php?action=index", {jax_type: 'update_other', ar_id: id,type:type,value:value, w_type:$("#w_type").val() },
		function(data){
	
			});
	}
}

function  check_info(w_type,id,check_tag,td_check_id,length,type)
{
	value = ($('#'+check_tag).html());
	value = value.replace(/"/g,'&quot;');
	$("#"+check_tag).remove();
	$("#"+td_check_id).html('<input type="text" id="'+check_tag+'"  value="'+value+'"   style="width:'+length+'px" />');
	$("#"+check_tag).focus();
	$("#"+check_tag).blur( function () 
	{ 
	  
		var check_value = $('#'+check_tag).val();		
		
		if(type == 'p_page_click' || type == 'sort'  || type=='ar_count')
		{
			check_value = parseInt(check_value);
		}	
	
		var str ="<span   id='"+check_tag+"' >"+check_value+"</span>";
		
		$("#"+td_check_id).html("");
		$("#"+td_check_id).html(str);
		
		$("#"+check_tag).mouseout( function () { check_css(check_tag,0); }); 
		$("#"+check_tag).mouseover( function () { check_css(check_tag,1); }); 
		
		$("#"+check_tag).click( function () { check_info(w_type,id,check_tag,td_check_id,length,type); }); 
		
		if(type=='sort')
		{
			$.get("/wondershare/category.php?action=index", { jax_type: 'sort_order', cat_id: id,sort_order:check_value },
			function(data){});  
		}else if(type=='ar_title')
		{
			$.get("/wondershare/article.php?action=index", { jax_type: 'update_title',w_type:w_type, ar_id: id,ar_title:check_value },
			function(data){
			
				}); 
		}
		else if(type=='ar_count')
		{
			$.get("/wondershare/article.php?action=index", {jax_type: 'update_count', ar_id: id,ar_count:check_value },
			function(data){}); 
		}else if(type=='tag_name')
		{
			$.get("/wondershare/tag.php?action=index", { jax_type: 'update_tag_name', tag_id: id,tag_name:check_value,w_type:$("#w_type").val() },
			function(data){
				
				});    
		}else if(type=='tag_click_count')
		{
			$.get("/wondershare/tag.php?action=index", { jax_type: 'update_click_count', tag_id: id,tag_click_count:check_value },
			function(data){});    
		}
	});
}



function  check_css(sort_tag,type)
{
	if(type==1)
	{
		$("#"+sort_tag).css({  "background": "blue","color": "#ff0011"}); 
	}
	else
	{
		$("#"+sort_tag).css({ "background": "","color":""}); 
	}
	
}

function del_cat(cat_id,type,w_type)
{
	var count = parseInt($('#count_'+cat_id).html());
	if(count>0)
	{
		if(type == 1)	
		{
			alert('不能删除此分类,此分类下面还有文章！');
		}else if(type == 2)
		{
			alert('不能删除此分类,此分类下面还有产品！');
		}
		return false;
	}
	$.get("/wondershare/category.php?action=index", { jax_type: 'del_category', cat_id: cat_id,w_type:w_type },
	function(data)
	{
		if(data == -1)
		{
			alert('不能删除此分类,此分类下面还有子分类！') ;
			return false;
		}else
		{
			$.each(data, function(i,item){
				var str = '_'+item.cat_id;
				$("tr[id*="+str+"]").remove();
			});
		}
	},'json'); 
}

function  submit_cat(type_str,type,cat_id,cat_series,w_type )
{
	
	var cat_name = $("#cat_name").val();
	var parent_id = $("#parent_id").val();
	var type = $("#type").val();
	
	if(cat_name.replace(/(^\s*)|(\s*$)/g, "")=="")
	{
		alert('分类名称不能为空！');
		$("#cat_name").focus();
		return false;
	}
	if(type_str == 'add')
	{
		$.get("/wondershare/category.php?action=index", { jax_type: 'repeat_name', cat_name: cat_name,type:type,w_type:w_type},
		function(data)
		{
			if(data !=  0)
			{
				/*alert('分类名称重复,请重新填写！');
				$("#cat_name").val('');
				$("#cat_name").focus();
				return false;*/
				//打开分类名称重复检验  ---zhangqian
				more_grades(type_str,cat_id,cat_series,w_type);
			}else
			{
				more_grades(type_str,cat_id,cat_series,w_type);
			}
		});
	
	}else if(type_str == 'edit')
	{
		
		$.get("/wondershare/category.php?action=index", { jax_type: 'repeat_name', cat_name: cat_name,cat_id:cat_id,type:type,w_type:w_type},
		function(data)
		{
			
			if(data !=  0)
			{
				/*alert('分类名称重复,请重新填写！');
				$("#cat_name").val('');
				$("#cat_name").focus();
				return false;*/
				//打开分类名称重复检验  ---zhangqian
				more_grades(type_str,cat_id,cat_series,w_type);
			}else
			{
				more_grades(type_str,cat_id,cat_series,w_type);
			}
		});
	
	}
} 

function more_grades(type_str,cat_id,cat_series,w_type)
{
	var cat_name = $("#cat_name").val();
	var parent_id = $("#parent_id").val();
	$.get("/wondershare/category.php?action=index", { jax_type: 'parent_series', parent_id: parent_id ,cat_id:cat_id ,
	cat_series:cat_series,w_type:w_type},
	function(data){
		if(data == -1)
		{
			alert('所修改的分类下面有子类 累计起来超过三级，请重新修改！');
			$("#cat_name").focus();
			return false;
		}else
		{
			if(data > 2)
			{
				alert('分类不能超过三级，请重新选择！');
				$("#cat_name").focus();
				return false;
			}else
			{
				
				operation_cat(type_str,w_type);
			} 
		}
	});
}

function  operation_cat(type_str,w_type)
{
	var cat_name = $("#cat_name").val();
	var parent_id = $("#parent_id").val();
	var sort_order = $("#sort_order").val();
	var type = $("#type").val();
	var recommended = $("#recommended").val();
	
	var cat_intro = $("#cat_intro").val();
	var cat_image = $("#cat_image").val();
	var cat_desc = $("#cat_desc").val(); 
	var cat_thumb = $("#cat_thumb").val(); 
	var cat_series = $("#cat_series").val(); 
	var google_code_article = $("#google_code_article").val(); 
	var google_code_guide = $("#google_code_guide").val(); 
	var google_code_buy = $("#google_code_buy").val(); 
	var google_code_oview = $("#google_code_oview").val(); 
	
	var google_code_install = $("#google_code_install").val(); 
	var google_code_uninstall = $("#google_code_uninstall").val(); 
	var google_code_register = $("#google_code_register").val(); 
	
  	var obj = $("#is_hot"); 
	  if($(obj).attr("checked")){ 
		  var is_hot = 1;
	  }else{ 
		  var is_hot = 0;
	  } 

	if(type_str == 'edit')
	{
	
	if(parent_id == $("#cat_id").val() )
	{
		alert('上级分类不能修改为自己！')
	}else
	{
			
		$.post("/wondershare/category.php?action=index", 
		{ jax_type: 'update_category', cat_name: cat_name,parent_id:parent_id,sort_order:sort_order,type:type,cat_thumb:cat_thumb,
		cat_intro:cat_intro,cat_id:$("#cat_id").val(),cat_image:cat_image,cat_desc:cat_desc,
		recommended:recommended,w_type:w_type,google_code_article:google_code_article,google_code_guide:google_code_guide,
		google_code_buy:google_code_buy,google_code_oview:google_code_oview,google_code_install:google_code_install,
		google_code_uninstall:google_code_uninstall,google_code_register:google_code_register,cat_series:cat_series,is_hot:is_hot},
		
		function(data){
	
			if(data == 1)
			{
				alert("修改成功！");
				window.location.href="/wondershare/category.php?action=index&type="+type+"&w_type="+w_type;
			}else if(data == 2)
			{
				alert("不能修改为自己的子类！");
			}else
			{
				alert('由于系统问题，而导致无法修改！')
			}
		
		});   
	}
	}else if(type_str == 'add')
	{
		$.post("/wondershare/category.php?action=index", 
		{jax_type: 'add_category', cat_name: cat_name,parent_id:parent_id,sort_order:sort_order,type:type,cat_thumb:cat_thumb,
		cat_intro:cat_intro,cat_image:cat_image,cat_desc:cat_desc,recommended:recommended,w_type:w_type,
		google_code_article:google_code_article,google_code_guide:google_code_guide,google_code_buy:google_code_buy,
		google_code_oview:google_code_oview,google_code_install:google_code_install,google_code_uninstall:google_code_uninstall,
		google_code_register:google_code_register,is_hot:is_hot},
		function(data){
			if(data == 1)
			{
				alert("增加成功！");
				window.location.href="/wondershare/category.php?action=index&act=add&type="+type+"&w_type="+w_type;
			}else
			{
				alert('由于系统问题，而导致无法增加！')
			}
		}); 
	}
}









